import mysql from 'mysql2/promise';
/**
 * MySQL数据库连接实例
 * 初始化为null，在异步连接建立后赋值
 * 使用前需检查连接状态
 */
let connection: mysql.Connection | null = null;
(async () => {
    try {
        connection = await mysql.createConnection({
            host: 'localhost',
            user: 'root',
            password: '1234',
            database: 'userdb',
        });
        console.log('MySQL connection established successfully');
    } catch (error) {
        console.error('MySQL connection failed:', error);
        connection = null;
    }
})();

export default connection;